#include <stdio.h>
#include <stddef.h>

// 定义宏：打印单个字段的字节内容
#define PRINT_FIELD_BYTES(structPtr, field) \
    do { \
        const unsigned char *fieldPtr = (const unsigned char *)(structPtr) + offsetof(typeof(*(structPtr)), field); \
        size_t fieldSize = sizeof(((typeof(*(structPtr)) *)0)->field); \
        printf("Field: %-10s, Offset: %2zu, Size: %2zu, Bytes: ", #field, offsetof(typeof(*(structPtr)), field), fieldSize); \
        for (size_t j = 0; j < fieldSize; j++) { \
            printf("%02x ", fieldPtr[j]); \
        } \
        printf("\n"); \
    } while (0)

#define PRINT_STRUCT_FIELDS(structPtr, field) \
    do { \
        PRINT_FIELD_BYTES(structPtr, field); \
    } while (0)

// 示例结构体 1
typedef struct {
    int id;
    char name[20];
    float score;
} MyStruct;

int main() {
    // 创建 MyStruct 实例并初始化
    MyStruct myStruct = {123, "Alice", 89.5f};
    printf("Printing MyStruct:\n");
    PRINT_STRUCT_FIELDS(&myStruct, id);
    PRINT_STRUCT_FIELDS(&myStruct, name);
    PRINT_STRUCT_FIELDS(&myStruct, score);
    printf("\n");

    return 0;
}